﻿using INTEX.DataBase;
using ReflectionStudio.Core.Events;
using System;
using System.Collections.Generic;
using System.Data;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using WPFExcelReport.ViweModels;
using System.Data.OracleClient;
using INTEX.DataBase.Tools;
namespace WPFExcelReport
{
    /// <summary>
    /// Interaction logic for SETUPABON.xaml
    /// </summary>
    public partial class ITXDBQUERY
    {
        ViewModelBase vm;
        ITXEXRPT ITXEXRPT;
        
        public ITXDBQUERY()
        {
            InitializeComponent();
            vm = new ViewModelBase();
            this.DataContext = vm;
            ITXEXRPT = new ITXEXRPT();
            ITXEXRPT.Root = "C:\\IntexReport";
            ITXEXRPT.strCompany = app.company;
            ITXEXRPT.PrintType = "OpenExcel";
        }
        #region=========Property=========

        public ApplicationBase app
        {
            get
            {
                return ApplicationBase.Instance;
            }
        }
        public INTEXDBC INTEXDBC
        {
            get
            {
                return app.INTEXDBC;
            }
        }

        #endregion
        DataSet setResult = null;
        private void Load_Click(object sender, RoutedEventArgs e)
        {
           
            try
            {
                string Query =txtQuery.Text;
                OracleCommand command = new OracleCommand();
                OracleCommand or1 = INTEXDBC.OracleDB.CreateCommand();
                or1.CommandText = Query;
                setResult = INTEXDBC.Connect2Proxy(or1); 
                //dlgResult.ItemsSource = setResult.Tables[0].Rows;
                dlgResult.DataContext = setResult.Tables[0];
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }
        private void btnPrint_Click(object sender, EventArgs e)
        {
            ITXEXRPT.dsSource = setResult;
            ITXEXRPT.DocType = "ABCOMPARE";
            ITXEXRPT.strExcelFile = @"ITX\ITXABDOC.xls";
            string filename = (string)ITXEXRPT.WriteExcelReport();
        }
    }
}
